package test.netty.io.echo;

import java.util.concurrent.atomic.AtomicLong;
import java.util.logging.Logger;

import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.buffer.ChannelBuffers;
import org.jboss.netty.channel.ChannelHandler;
import org.jboss.netty.channel.SimpleChannelUpstreamHandler;

public class EchoClientHandler extends SimpleChannelUpstreamHandler {
	private static final Logger logger = Logger.getLogger( EchoClientHandler.class.getName()); 
	/**
	 * @uml.property  name="firstMessage"
	 * @uml.associationEnd  multiplicity="(1 1)"
	 */
	private final ChannelBuffer firstMessage; 
	/**
	 * @uml.property  name="transferredBytes"
	 */
	private final AtomicLong transferredBytes = new AtomicLong(); 
	
	public EchoClientHandler(int firstMessageSize) {
		if(firstMessageSize <0 )
		{
			throw new IllegalArgumentException("firstMessageSize: " + firstMessageSize); 					
		}
		firstMessage = ChannelBuffers.buffer(firstMessageSize);
		for(int i=0; i< firstMessage.capacity();i++){
			firstMessage.writeByte((byte) i);  
		}
	}

	public long getTransferredBytes(){
		return transferredBytes.get(); 
	}
	
}
